<?php
// get Language Pack for user.. languageID from session
if(
	isset($_SESSION['divelog']['login']['languageID']) && 
	!empty($_SESSION['divelog']['login']['languageID']) && 
	is_numeric($_SESSION['divelog']['login']['languageID']) &&
	floor($_SESSION['divelog']['login']['languageID']) == $_SESSION['divelog']['login']['languageID']
	)
{
    $query = "    SELECT 
                    LW.Variable,
                    IF(
                        LT.Translation IS NULL,
                        LW.Word,
                        LT.Translation
                    ) AS Value
                FROM LanguageWords AS LW
                    LEFT JOIN LanguageWordTranslations AS LT ON LT.WordID = LW.ID
                                                        AND LT.LanguageID = '".str_replace("'","",$_SESSION['divelog']['login']['languageID'])."'";
}

//no languageID, default language(en)
else
{
        $query = "    SELECT 
                        LW.Variable,
                        LW.Word AS Value 
                    FROM LanguageWords AS LW";
}

if($result = $mysqli->query($query))
{
	while($row = $result->fetch_assoc())
	    define($row['Variable'], $row['Value']);
}
else
	echo $mysqli->error;
?>